<include file="../header" />
<body class="J_scroll_fixed">
    
    <script>
         function initialize(){
                var shopId = $('select[name=shopId]').val();
                $.ajax({
                    type: "post",
                    url: "{:U('coach/getCoachListByShop')}",
                    data: {shopId:shopId},
                    dataType: "json",
                    success: function(data){
                        $("#selectCoach").html(data);
                    
                    }
                });
            }
        $(document).ready(function() {
            
            initialize();//初始化       

            $('select[name=shopId]').change(function() {
                
                var shopId = $(this).val();
                
                $.ajax({
                    type: "post",
                    url: "{:U('coach/getCoachListByShop')}",
                    data: {shopId:shopId},
                    dataType: "json",
                    success: function(data){
                        $("#selectCoach").html(data);
                    
                    }
                });
                
            });
        
            
            $('input[name=number]').keyup(function() {
                
                var price = $('input[name=price]').val();
                
                var number = $(this).val();
                
                 //正则判断是否为数字
                if(!/^\d+$/.test(number)||number<=0) {
                    layer.msg('课次应为正整数!');
                    return false;
                }
                
                number = number > 0 ? number : 0;
                price = price >0 ? price : 0;
                
                
                $('#fee').html(number*price+'元');
                
            });
            $('input[name=price]').keyup(function() {
                
                var number = $('input[name=number]').val();
                
                var price = $(this).val();
                
                 //正则判断是否为数字
                if(!/^\d+$/.test(price)||price<=0) {
                    layer.msg('单价应为正整数!');
                    return false;
                }
                
                number = number > 0 ? number : 0;
                 price = price >0 ? price : 0;
                $('#fee').html(number*price+'元');
                
            });

            $('button#send').click(function () {

                var shopId = $('select[name=shopId]').val();
                var coachId = $('select[name=coachId]').val();
                var price = $('input[name=price]').val();
                var number = $('input[name=number]').val();
               
                if(shopId == 0 || coachId == 0 ) {
                    layer.msg('请选择店铺及教练，不能为空!');
                    return false;
                }
                
                if(!/^\d+$/.test(price)||price===''||price===null||price<=0) {
                    layer.msg('单价应为正整数且不能为空!');
                    return false;
                }
                 //正则判断是否为数字
                if(!/^\d+$/.test(number)||number===''||number===null||number<=0) {
                    layer.msg('课数应为正整数且不能为空!');
                    return false;
                }else{
                    $("form#form").submit();
                }
               
               
            });
           
        });

    </script>
    
	<div class="wrap jj">
		<div class="common-form">
			<form method="post" class="form-horizontal J_ajaxForm" id="form" action="{:U('vip/buyCoursePost')}">
                            <input type='hidden' name='vipId' value='{$id}' />
				<fieldset>
					<div class="control-group">
						<label class="control-label">店铺选择:</label>
						<div class="controls">
                                                    {:getShopSelectHtml($shopId,1)}
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">教练选择:</label>
						<div class="controls" id="selectCoach">
                                                    <select name="coachId" >
                                                        <option value="0">全部</option>
                                                    </select>
						</div>
					</div>
                                       <div class="control-group">
						<label class="control-label">课程单价:</label>
						<div class="controls" >
							<input type="text" name="price" placeholder="请输入整数"/>
						</div>
					</div>
                                        <div class="control-group">
						<label class="control-label">课次:</label>
						<div class="controls" id="number">
							<input type="text" name="number" placeholder="请输入整数"/>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">应付费用:</label>
						<label class="controls" id="fee">0元</label>
					</div>
				</fieldset>
				<div class="form-actions">
					<button type="button" class="btn btn-primary btn_submit" id="send">购买</button>
				</div>
			</form>
		</div>
	</div>
	<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>